﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.SelectMap
{
    class Selection
    {
        private string Thongbao;
        private string name;
        private Texture2D background;
        private Texture2D Nutbam;
        private Texture2D chedo;
        private bool isOpen;
        private bool isVisible;
        private bool touchBando;
        private bool touchchoi;
        private int level;
        SpriteFont mini;
        public Selection()
        {
            Thongbao = "";
            name = "";
            isOpen = false;
            isVisible = false;
            level = 1;
            touchBando = false;
            touchchoi = false;
        }
        public void set(Thanh thanh)
        {
            isOpen = thanh.isOpen();
            if (thanh.isOpen())
            {
                Thongbao = "";
                name = thanh.getName();
                //if (thanh.getIndex() == 9) Thongbao = "Thành đang được phát triển";
            }
            else
            {
                name = "THÔNG BÁO";
                Thongbao = thanh.getNotify();
            }
            isVisible = true;
        }
        public void Load(ContentManager content)
        {
            background = content.Load<Texture2D>("images/menu/infoFrame");
            Nutbam = content.Load<Texture2D>("images/playScreen/endGame");
            chedo = content.Load<Texture2D>("images/selectMap/difficulty");
            mini = content.Load<SpriteFont>("fonts/font1");
        }
        public void Draw(SpriteBatch sprite, SpriteFont font)
        {
            sprite.Draw(background, new Vector2(100, 20), new Rectangle(0, 0, 379, 265),
                                                Color.White, 0, Vector2.Zero, 1.6f, SpriteEffects.None, 0);
            sprite.DrawString(font, name, new Vector2(330, 40), Color.White);
            if (isOpen)// && SelectMapAndStore.levelselected != 9)
            {
                sprite.DrawString(font, "Chọn chế độ chơi", new Vector2(300, 70), Color.White);
                if (level == 1)
                {
                    sprite.Draw(chedo, new Vector2(130, 150), new Rectangle(0, 184, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(chedo, new Vector2(130, 150), new Rectangle(0, 0, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                if (level == 2)
                {
                    sprite.Draw(chedo, new Vector2(277, 150), new Rectangle(147, 184, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(chedo, new Vector2(277, 150), new Rectangle(147, 0, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                if (level == 3)
                {
                    sprite.Draw(chedo, new Vector2(423, 150), new Rectangle(294, 184, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(chedo, new Vector2(423, 150), new Rectangle(294, 0, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                if (level == 4)
                {
                    sprite.DrawString(mini, "Bạn sẽ được thưởng xu nếu vượt qua mức độ khó nhất.", new Vector2(160, 300), Color.White);
                    sprite.Draw(chedo, new Vector2(571, 150), new Rectangle(441, 184, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(chedo, new Vector2(571, 150), new Rectangle(441, 0, 147, 184), Color.White, 0, Vector2.Zero, 0.7f, SpriteEffects.None, 0);
                }
                if (touchBando)
                {
                    sprite.Draw(Nutbam, new Vector2(150, 350), new Rectangle(251, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(Nutbam, new Vector2(150, 350), new Rectangle(0, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                if (touchchoi)
                {
                    sprite.Draw(Nutbam, new Vector2(500, 350), new Rectangle(251, 210, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(Nutbam, new Vector2(500, 350), new Rectangle(0, 210, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
            }
            else
            {
                sprite.DrawString(font, Thongbao, new Vector2(280, 190), Color.White);
                if (touchBando)
                {
                    sprite.Draw(Nutbam, new Vector2(330, 300), new Rectangle(251, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(Nutbam, new Vector2(330, 300), new Rectangle(0, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
            }
        }
        public bool getVisible()
        {
            return isVisible;
        }
        public void setVisible(bool k)
        {
            isVisible = k;
            level = 1;
            touchBando = false;
            touchchoi = false;
        }
        public void isChangeMode(Vector2 touch)
        {
            if (touch.Y >= 150 && touch.Y <= 279)
            {
                if (touch.X >= 130 && touch.X <= 233) { level = 1; MainPage.PlayHieuUng("Click", false); }
                if (touch.X >= 277 && touch.X <= 380) { level = 2; MainPage.PlayHieuUng("Click", false); }
                if (touch.X >= 423 && touch.X <= 526) { level = 3; MainPage.PlayHieuUng("Click", false); }
                if (touch.X >= 571 && touch.X <= 674) { level = 4; MainPage.PlayHieuUng("Click", false); }
            }
            SelectMapAndStore.capdoselected = level;
        }
        public bool isSelectBando(Vector2 touch)
        {
            if (isOpen)// && SelectMapAndStore.levelselected != 9)
            {
                if (touch.X >= 150 && touch.X <= 300 && touch.Y >= 350 && touch.Y <= 392)
                {
                    MainPage.PlayHieuUng("Click", false);
                    touchBando = true;
                    return true;
                }
                else
                {
                    touchBando = false;
                    return false;
                }
            }
            else
            {
                if (touch.X >= 330 && touch.X <= 480 && touch.Y >= 300 && touch.Y <= 342)
                {
                    MainPage.PlayHieuUng("Click", false);
                    touchBando = true;
                    return true;
                }
                else
                {

                    touchBando = false;
                    return false;
                }
            }
        }
        public bool isSelectChoi(Vector2 touch)
        {
            if (isOpen)// && SelectMapAndStore.levelselected != 9)
            {
                if (touch.X >= 500 && touch.X <= 650 && touch.Y >= 350 && touch.Y <= 392)
                {
                    MainPage.PlayHieuUng("Click", false);
                    touchchoi = true;
                    return true;
                }
                else
                {
                    touchchoi = false;
                    return false;
                }
            }
            else
            {
                touchchoi = false;
                return false;
            }
        }
    }
}
